package com.tianji.learning.service.impl;

import com.tianji.api.client.aigc.AigcClient;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.dto.ReplyDTO;
import com.tianji.learning.domain.po.InteractionQuestion;
import com.tianji.learning.service.AigcService;
import com.tianji.learning.service.IInteractionReplyService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class AigcServiceImpl implements AigcService {
    @Autowired
    private IInteractionReplyService replyService;
    @Autowired
    private AigcClient aigcClient;
    @Async
    @Override
    public void userModelAnswerQuestion(QuestionFormDTO questionDTO, InteractionQuestion question, Long userId) {
        UserContext.setUser(userId);
        String answer = aigcClient.text(questionDTO.getTitle() + questionDTO.getDescription());

        ReplyDTO replyDTO = ReplyDTO.builder()
                .userId(9999L)
                .content(answer)
                .anonymity(false)
                .questionId(question.getId())
                .isStudent(false)
                .build();
        replyService.saveReply(replyDTO);
    }
}
